#include "pscan.hpp"

void scan() {
  for (int i = 0; i < 65535; i++) {
    int sockfd;
    struct sockaddr_in tower;

    if (inet_pton(AF_INET, "127.0.0.1", &tower.sin_addr) < 1) {
      fprintf(stderr, "problem loading IP address\n");
      exit(EXIT_FAILURE);
    }

    memset(&tower, 0, sizeof(tower));
    tower.sin_family = AF_INET;
    tower.sin_addr.s_addr = inet_addr("127.0.0.1");
    tower.sin_port = htons(i);

    if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) < 0 ) {
      close(sockfd);
      continue;
    }

    if (connect(sockfd, (struct sockaddr*)&tower, sizeof(tower)) == 0) {
      open_ports.push_back(i);
    }

    close(sockfd);

  }
}

int main() {
  int num_threads = thread::hardware_concurrency();
  printf("Thread avaliable: %d\n", num_threads);

  scan();

}
